def decodeString(s):

    def decode(i):
        #给变量赋值
        res, num="",0

        #while循环
        while (i < len(s)):
            if "0" < s[i] <="9":
                num = num*10 + int(s[i])
            elif s[i] == '[':
                i,tep = decode(i + 1)
                res =res + num * tep
                num = 0
            elif s[i] == ']':
                return i, res
            else:
                res = res + s[i]
            i = i + 1
        return res
    return decode(0)
print (decodeString('3[ab]2[cd]'))






